package com.example.chapter0;


import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ButtonEnabledActivity extends AppCompatActivity implements View.OnClickListener {

    private Button test;
    private TextView view1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_enabled);
        Button btn_enable = findViewById(R.id.btn_enable);
        Button btn_disable = findViewById(R.id.btn_disable);
        test = findViewById(R.id.btn_test);
        view1 = findViewById(R.id.tv_result);
        btn_enable.setOnClickListener(this);
        btn_disable.setOnClickListener(this);
        test.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId()==R.id.btn_enable){
            test.setEnabled(true);
        } else if (view.getId()==R.id.btn_disable){
            test.setEnabled(false);
        } else if (view.getId()==R.id.btn_test){
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
            String desc = String.format("%s 您点击了按钮： %s", sdf.format(new Date()), ((Button) view).getText());
            view1.setText(desc);
        }
    }
}